package cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.controller;

import cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.form.ContractSellDefyOverdueApplicationInfoNewForm;
import cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.form.ContractSellDefyOverdueApplicationInfoEditForm;
import cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.form.ContractSellDefyOverdueApplicationInfoQueryForm;
import cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.form.ContractSellDefyOverdueApplicationInfoDeleteForm;
import cn.terminus.web.customer.contractselldefyoverdueapplicationinfo.form.ContractSellDefyOverdueApplicationInfoGetsForm;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.param.ContractSellDefyOverdueApplicationInfoNewParam;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.param.ContractSellDefyOverdueApplicationInfoEditParam;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.param.ContractSellDefyOverdueApplicationInfoQueryParam;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.param.ContractSellDefyOverdueApplicationInfoDeleteParam;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.param.ContractSellDefyOverdueApplicationInfoGetsParam;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.result.ContractSellDefyOverdueApplicationInfoResult;
import cn.terminus.client.customer.contractselldefyoverdueapplicationinfo.service.ContractSellDefyOverdueApplicationInfoService;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.exception.ServiceException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.result.common.context.TerminusCallContext;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

/**
 * 合同出售办证违约(ContractSellDefyOverdueApplicationInfo)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine ContractSellDefyOverdueApplicationInfo 合同出售办证违约
 * @since 2021-07-21 11:18:35
 */
@RestController
// todo 请修改path
@RequestMapping("/contractSellDefyOverdueApplicationInfo")
@Api(value = "合同出售办证违约(ContractSellDefyOverdueApplicationInfo)控制层")
public class ContractSellDefyOverdueApplicationInfoController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private ContractSellDefyOverdueApplicationInfoService contractSellDefyOverdueApplicationInfoService;

    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/add 合同出售办证违约新增
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约新增
     * @apiDescription 合同出售办证违约新增
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiParam (RequestBody) {String} lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody ContractSellDefyOverdueApplicationInfoNewForm form) {
        ContractSellDefyOverdueApplicationInfoNewParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoNewParam.class);
        try {
            return contractSellDefyOverdueApplicationInfoService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("新增合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/edit 合同出售办证违约编辑
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约编辑
     * @apiDescription 合同出售办证违约编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiParam (RequestBody) {String} lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody ContractSellDefyOverdueApplicationInfoEditForm form) {
        ContractSellDefyOverdueApplicationInfoEditParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoEditParam.class);
        try {
            return contractSellDefyOverdueApplicationInfoService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/delete 合同出售办证违约删除
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约删除
     * @apiDescription 合同出售办证违约删除
     * @apiParam (RequestBody) {String[]} ids  合同出售办证违约ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody ContractSellDefyOverdueApplicationInfoDeleteForm form) {
        ContractSellDefyOverdueApplicationInfoDeleteParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoDeleteParam.class);
        try {
            return contractSellDefyOverdueApplicationInfoService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/gets 合同出售办证违约详情
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约详情
     * @apiDescription 合同出售办证违约详情
     * @apiParam (RequestBody) {String[]} ids  合同出售办证违约ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同出售办证违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约详情查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellDefyOverdueApplicationInfoResult>> gets(@RequestBody ContractSellDefyOverdueApplicationInfoGetsForm form) {
        ContractSellDefyOverdueApplicationInfoGetsParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoGetsParam.class);
        try {
            return contractSellDefyOverdueApplicationInfoService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/query 合同出售办证违约查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约查询
     * @apiDescription 合同出售办证违约查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiParam (RequestBody) {String} lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同出售办证违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellDefyOverdueApplicationInfoResult>> query(@RequestBody ContractSellDefyOverdueApplicationInfoQueryForm form) {
        ContractSellDefyOverdueApplicationInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoQueryParam.class);
        try {
            return contractSellDefyOverdueApplicationInfoService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyOverdueApplicationInfo/page 合同出售办证违约分页查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyOverdueApplicationInfo
     * @apiName 合同出售办证违约分页查询
     * @apiDescription 合同出售办证违约分页查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiParam (RequestBody) {String} lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    合同出售办证违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationWithinDay  办证逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationWithinDayUnitCode  办证逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateOverdueApplicationOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateOverdueApplicationPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateOverdueApplicationPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "合同出售办证违约分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<ContractSellDefyOverdueApplicationInfoResult>> page(@RequestBody ContractSellDefyOverdueApplicationInfoQueryForm form) {
        ContractSellDefyOverdueApplicationInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyOverdueApplicationInfoQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return contractSellDefyOverdueApplicationInfoService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询合同出售办证违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询合同出售办证违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
